package com.lu.widgets.demo;

import com.lu.widgets.R;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.util.DisplayMetrics;

public class ScreenParams extends PreferenceActivity {// 只是用来显示屏幕参数的，不需要设置对应的保存设置的Preference
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Display the fragment as the main content.
		getFragmentManager().beginTransaction()
				.replace(android.R.id.content, new PrefsFragment()).commit();
	}

	public static class PrefsFragment extends PreferenceFragment {

		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			// Load the preferences from an XML resource
			addPreferencesFromResource(R.xml.screen_params);

			DisplayMetrics dm = getActivity().getApplicationContext()
					.getResources().getDisplayMetrics();
			// My Device
			findPreference("heightWidthPixels").setTitle(
					dm.widthPixels + " x " + dm.heightPixels);
			findPreference("xyDpi").setTitle(dm.xdpi + " x " + dm.ydpi);
			findPreference("density").setTitle(String.valueOf(dm.density));
			findPreference("densityDpi")
					.setTitle(String.valueOf(dm.densityDpi));
			findPreference("scaledDensity").setTitle(
					String.valueOf(dm.scaledDensity));

			// Standard Defination
			findPreference("DENSITY_DEFAULT").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_DEFAULT));
			findPreference("DENSITY_LOW").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_LOW));
			findPreference("DENSITY_MEDIUM").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_MEDIUM));
			findPreference("DENSITY_HIGH").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_HIGH));
			findPreference("DENSITY_XHIGH").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_XHIGH));
			findPreference("DENSITY_XXHIGH").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_XXHIGH));
			findPreference("DENSITY_TV").setTitle(
					String.valueOf(DisplayMetrics.DENSITY_TV));
		}
	}
}
